<%--
  Created by IntelliJ IDEA.
  User: 22328
  Date: 2021/2/7
  Time: 20:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>账号切换</title>
    <link href="./lib/layui/css/layui.css" rel="stylesheet" type="text/css">
    <script src="./lib/layui/layui.js" type="text/javascript"></script>
</head>
<body>
<div class="layui-form" onsubmit="return false">
    <div class="layui-form-item" style="margin-top: 20px">
        <label for="username" class="layui-form-label">
            登录名
        </label>
        <div class="layui-input-inline" style="width: 200px">
            <input type="text" id="username" name="username" value="" placeholder="请输入用户名"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label for="password" class="layui-form-label">
            密码
        </label>
        <div class="layui-input-inline" style="width: 200px">
            <input type="password" id="password" name="password" value="" placeholder="请输入密码"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">
        </label>
        <button id="change_btn" class="layui-btn">
            切换
        </button>
    </div>
</div>
</body>
<script src="./js/jquery-3.1.0.min.js"></script>
<script>
    $(function () {
        $("#change_btn").click(function () {
            var username = $("#username").val();
            var password = $("#password").val();
            $.ajax({
                url: "./checkLogin",
                type: "post",
                data: {username: username, password: password},
                success: function (res) {
                    if (res != null && res !== '') {
                        if (res.role.roleName === '管理员' || res.role.roleName === '商家') {
                            window.top.location.href = "./adminMenu?username=" + username;
                        }
                        if (res.role.roleName === '普通用户') {
                            //如果该用户是普通用户就跳转到前台主页面
                            window.location.href = "./main?username=" + username;
                        }
                        if (res.status === 0){
                            alert("用户已经被禁用，请联系客服");
                        }
                    } else {
                        alert("用户名或密码错误");
                    }
                },
                error: function () {
                    alert("404.html页面");
                }
            });
        });
    });
</script>
</html>
